﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace DIProject.ReceptionGoods
{
    public partial class FillialNakl : Form
    {
        Int32 _docId;
        string _docNumber;
        string _sellerName;
        DateTime _docDate;
        string _fillialName;
        string _docNum;
        public FillialNakl(Int32 docId, string docNumber, string sellerName, DateTime docDate,string fillialName,string docNum)
        {
            _docId = docId;
            _docDate = docDate;
            _docNumber = docNumber;
            _sellerName = sellerName;
            _fillialName = fillialName;
            _docNum = docNum;
            InitializeComponent();
        }
        public string Reason
        {
            get
            {
                return _sellerName + " " + _docNumber + " " + _docDate.ToString("D");
            }
        }
        private string ReportFilePath
        {
            get
            {
                string result = string.Empty;
                string systemPath = System.Configuration.ConfigurationManager.AppSettings["ReportsPath"];
                if (string.IsNullOrEmpty(systemPath))
                {
                    throw new Util.DIException("Требуется задать путь к программе в конфигурационном файле");
                }
                string reportPath = System.Configuration.ConfigurationManager.AppSettings["fillialNakl"];
                if (string.IsNullOrEmpty(reportPath))
                {
                    throw new Util.DIException("Требуется задать путь файлам отчета");
}
                return systemPath + reportPath;
            }
            
        }
        public FillialNakl()
        {
            InitializeComponent();
        }

        private void crystalReportViewer1_Load(object sender, EventArgs e)
        {
            DataSets.waybillsDataTableAdapters.CurrentNaklTableAdapter adapter = new DIProject.DataSets.waybillsDataTableAdapters.CurrentNaklTableAdapter();
            DataSets.waybillsData.CurrentNaklDataTable tab = adapter.GetData(_docId);
            FillialNaklPer1.FileName = this.ReportFilePath;
            FillialNaklPer1.Load();
            FillialNaklPer1.SetDataSource(tab as DataTable);
            FillialNaklPer1.SetParameterValue("FillialName", _fillialName);
            FillialNaklPer1.SetParameterValue("Reason", this.Reason);
            FillialNaklPer1.SetParameterValue("Id",this._docNum);// this._docId.ToString());
            FillialNaklPer1.SetParameterValue("DocDate", this._docDate);
            
        }
    }
}